package gestao_proj;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter;

/**
 * Painel inicial do projecto com a opcao de criar um novo projecto ou carregar
 * um novo
 * 
 * @author Omar Castro
 * 
 */
@SuppressWarnings("serial")
public class Start extends JPanel {
	private JFileChooser fc;
	public static JButton newProject, loadProject;
	public static FileFilter filtro = new FileFilter() {
		public boolean accept(File f) {
			if (f.isDirectory() || f.getName() != null
					&& f.getName().contains(".proj")) {
				return true;
			} else
				return false;
		}

		public String getDescription() {
			return "Project files";
		}

	};

	public Start(final Janela janela) {
		newProject = new JButton("New Project");
		loadProject = new JButton("Load Project");
		newProject.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				Janela.grafo = new Painel(new Projecto("Novo"));
				Janela.grafo.setBackground(Color.black);
				janela.setContentPane(Janela.grafo);
				janela.setSize(1000, 500);
				janela.setMinimumSize(new Dimension(850, 300));
			}

		});
		loadProject.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				fc = new JFileChooser();
				fc.addChoosableFileFilter(Start.filtro);
				int returnVal = fc.showOpenDialog(Start.this);
				if (returnVal == JFileChooser.APPROVE_OPTION) {
					File file = fc.getSelectedFile();
					Janela.grafo = new Painel(Data.loadProj(file));
					Janela.grafo.setBackground(Color.black);
					janela.setContentPane(Janela.grafo);
					janela.setSize(1000, 500);
				}
			}
		});
		add(newProject);
		add(loadProject);
	}

}
